package com.leetcode.partition3;

import com.leetcode.common.ListNode;

/**
 * @author `RKC`
 * @date 2021/9/10 10:04
 */
public class LC203移除链表元素 {

    public static ListNode removeElements(ListNode head, int val) {
        ListNode newHead = new ListNode();
        newHead.next = head;

        ListNode cur = newHead;
        while (cur.next != null) {
            if (cur.next.val != val) {
                cur = cur.next;
                continue;
            }
            cur.next = cur.next.next;
        }
        return newHead.next;
    }

    public static void main(String[] args) {
        ListNode node = new ListNode(7, new ListNode(7, new ListNode(7, new ListNode(7))));
        System.out.println(removeElements(node, 7));
    }
}
